package org.journal.service;

import org.journal.entity.UserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {

	private static final Logger log = LoggerFactory
			.getLogger(CustomUserDetailsService.class);

	@Autowired
	private UserService userService;

	public UserDetails loadUserByUsername(String username) {

		UserEntity user = userService.getUserByUsername(username);
		return userService.getUserAuthorizationDetails(user);

	}

	/*protected UserDetails createUserDetails(final String username,
			final UserDetails userFromUserQuery,
			final List<GrantedAuthority> combinedAuthorities) {

		boolean usernameBasedPrimaryKey = true;

		String returnUsername = userFromUserQuery.getUsername();

		if (!usernameBasedPrimaryKey) {
			returnUsername = username;
		}

		final UserDTO userToReturn = new UserDTO(returnUsername,
				userFromUserQuery.getPassword(), userFromUserQuery.isEnabled(),
				true, true, true, combinedAuthorities);
		userToReturn.setId(((UserDTO) userFromUserQuery).getId());

		return userToReturn;
	}*/

}
